package net.trustie.model;

import org.apache.commons.codec.digest.DigestUtils;

import net.trustie.utils.DateHandler;
import net.trustie.utils.StringHandler;
import core.AfterExtractor;
import core.Page;
import core.ValidateExtractor;
import us.codecraft.webmagic.model.annotation.ExtractBy;

public class apache_Model implements AfterExtractor, ValidateExtractor{
	

	private String project_url = "";
	
	@ExtractBy("//*div[@id='bodySection']/table/tbody/tr/td[2]/h2/text()")
	private String project_name = "";
    @ExtractBy("//*div[@id='bodySection']/table/tbody/tr/td[2]/div/p[2]/text()")
	private String project_descriprion = "";
    @ExtractBy("//*[@id='bodySection']/table/tbody/tr/td[2]/div/div[1]/div[1]/p/a/text()")
	private String download_url = "";
    @ExtractBy("//*[@id='bodySection']/table/tbody/tr/td[2]/div/table/tbody/tr[1]/td[2]/a/text()")
	private String languege = "";
    @ExtractBy("//*[@id='bodySection']/table/tbody/tr/td[2]/div/table/tbody/tr[2]/td[2]/allText()")
	private String categories;
    @ExtractBy("//*[@id='bodySection']/table/tbody/tr/td[2]/div/table/tbody/tr[5]/td[2]/a/text()")
	private String license = "";
	@ExtractBy("//*[@id='bodySection']/table/tbody/tr/td[2]/div/div[1]/div[2]/table/tbody/tr[5]/td[3]/text()")
	private String project_created_time = "";
	@ExtractBy("//*[@id='bodySection']/table/tbody/tr/td[2]/div/div[1]/div[2]/table/tbody/tr[2]/td[3]/text()")
	private String project_updated_time = "";
	
	private String extractTime = "";
	
	private int history = 0;
	
	private String urlMd5;
	private String source="apache";
	public String getExtractTime() {
		return extractTime;
	}
	public void setExtractTime(String extractTime) {
		this.extractTime = extractTime;
	}
	public String getSource() {
		return source;
	}
	public void setSource(String source) {
		this.source = source;
	}
	public String getIssue_link() {
		return issue_link;
	}
	public void setIssue_link(String issue_link) {
		this.issue_link = issue_link;
	}
	public String getMailing_link() {
		return mailing_link;
	}
	public void setMailing_link(String mailing_link) {
		this.mailing_link = mailing_link;
	}
//	@ExtractBy("//*div[@id='navigation_menu']/ul[3]/li[4]/a/@href")
//	private String issue_link;
//	@ExtractBy("//*div[@id='navigation_menu']/ul[3]/li[1]/a/@href")
//	private String mailing_link;
	
	@ExtractBy("//*[@id='bodySection']/table/tbody/tr/td[2]/div/table/tbody/tr[4]/td[2]/a/@href")
	private String issue_link;
	@ExtractBy("//*[@id='bodySection']/table/tbody/tr/td[2]/div/table/tbody/tr[3]/td[2]/a/@href")
	private String mailing_link;
	
	public void afterProcess(Page page){
// 处理project_url
		this.project_url = page.getPageUrl();
		this.urlMd5 = DigestUtils.md5Hex(this.project_url);
//处理project_created_time
		this.project_created_time = DateHandler.standardForDate(project_created_time);
//处理project_updated_time
		this.project_updated_time = DateHandler.standardForDate(project_updated_time);
//处理extractTime
		this.extractTime = DateHandler.getExtractTime();
		
//		System.out.println("issulink: " + this.issue_link);
//		System.out.println("mailinglink: " + this.mailing_link);
		
	}
	public void validate(Page page){
		if (StringHandler.isAtLeastOneBlank(this.project_url, this.project_name)) {
			page.setResultSkip(this, true);
			return;
		}
		
		if (!DateHandler.canFormatToDate( this.extractTime)) { 
			page.setResultSkip(this, true);
			return;
		}	
		}
	public String getProject_url() {
		return project_url;
	}
	public void setProject_url(String project_url) {
		this.project_url = project_url;
	}
	public String getProject_name() {
		return project_name;
	}
	public void setProject_name(String project_name) {
		this.project_name = project_name;
	}
	public String getProject_descriprion() {
		return project_descriprion;
	}
	public void setProject_descriprion(String project_descriprion) {
		this.project_descriprion = project_descriprion;
	}
	public String getDownload_url() {
		return download_url;
	}
	public void setDownload_url(String download_url) {
		this.download_url = download_url;
	}
	public String getLanguege() {
		return languege;
	}
	public void setLanguege(String languege) {
		this.languege = languege;
	}
	public String getCategories() {
		return categories;
	}
	public void setCategories(String categories) {
		this.categories = categories;
	}
	public String getLicense() {
		return license;
	}
	public void setLicense(String license) {
		this.license = license;
	}
	public String getProject_created_time() {
		return project_created_time;
	}
	public void setProject_created_time(String project_created_time) {
		this.project_created_time = project_created_time;
	}
	public String getProject_updated_time() {
		return project_updated_time;
	}
	public void setProject_updated_time(String project_updated_time) {
		this.project_updated_time = project_updated_time;
	}
	public String getextractTime() {
		return extractTime;
	}
	public void setextractTime(String extractTime) {
		this.extractTime = extractTime;
	}
	public int getHistory() {
		return history;
	}
	public void setHistory(int history) {
		this.history = history;
	}
	
}
